/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import DAO.*;
import Negocio.*;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumnModel;
import org.prevayler.Prevayler;
import org.prevayler.PrevaylerFactory;
import org.pushingpixels.flamingo.api.common.JCommandButton;
import org.pushingpixels.flamingo.api.common.JCommandToggleButton;
import org.pushingpixels.flamingo.api.common.icon.ImageWrapperResizableIcon;
import org.pushingpixels.flamingo.api.common.icon.ResizableIcon;
import org.pushingpixels.flamingo.api.ribbon.*;
import org.pushingpixels.flamingo.api.ribbon.resize.CoreRibbonResizePolicies;

/**
 *
 * @author Jeferson
 */
public class MWRibbon extends JRibbonFrame {

    private Prevayler prevayler;
    private Data dados;
    private AlunoTableModel atm;
    private GregorianCalendar gc = new GregorianCalendar();
    private CBPastaModel cbpm;
    private String localPath = System.getProperty("java.class.path");
    private String basedir = "BaseDados";
    private String sep = System.getProperty("file.separator");
    private String configFilename = "config.ini";
    private ResizableIcon appicon;
    private TableColumnModel tcm;
    private int modelRow = 0;
    private String path = localPath;
    
                
    /**
     * Creates new form MWRibbon
     */
    public MWRibbon() {
        try {
            
            atm = new AlunoTableModel(new ArrayList<Aluno>());
            cbpm = new CBPastaModel();
            
            path = localPath.substring(localPath.lastIndexOf("jar:")+4);
            //path = path.substring(0, path.lastIndexOf(sep));
            
            //Inicia os componentes
            initComponents();
            
            carregaConfigurações();
            startPrevayler(basedir);
            carregaDados();
            
            //Configura o calendário com a data atual
            gc.setTimeInMillis(System.currentTimeMillis());
            
            DefaultTableCellRenderer header = (DefaultTableCellRenderer) jXTable1.getTableHeader().getDefaultRenderer();
            header.setHorizontalAlignment(SwingConstants.CENTER);
            
            //Configura janela principal
            this.setSize(1000, 700);
            this.setLocationRelativeTo(null);
            
            //Cria o Ribbon
            createRibbonPanel();
            
            //Inicia a thread que tira snapshots a cada 30 min
            new SnapshotTimer(prevayler).start(); 
            
        } catch (IOException ex) {
            Logger.getLogger(MWRibbon.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(MWRibbon.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    //Carrega dados do banco
    public void carregaDados() {
        jLabel3.setText(basedir);
        dados = ((Data) prevayler.prevalentSystem());
        jLabel4.setText(""+dados.getSize());
        //Inicia modelos das tabelas e combobox
        atm = new AlunoTableModel(dados.getArrayAlunos());
        jXLabel11.setText("Total de Registros: "+dados.getArrayAlunos().size());
        cbpm = new CBPastaModel(dados.getArrayPastas());
        //Adiciona um listenner table model para redimensionar as colunas da tabela de acordo com o tamanho do
        //jpanel1, quando este for redimensionado
        atm.addTableModelListener(new TableModelListener() {

            @Override
            public void tableChanged(TableModelEvent e) {
                resizeColumns();
            }
        });
        jXTable1.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent event) {
                int viewRow = jXTable1.getSelectedRow();
                if (viewRow >= 0) {
                    modelRow = jXTable1.convertRowIndexToModel(viewRow);
                }
            }
        });

        jXTable1.setModel(atm);
        //resizeColumns();
        jComboBox3.setModel(cbpm);
    }

    //Inicia o prevayler
    private void startPrevayler(String dir) throws ClassNotFoundException, IOException {
        PrevaylerFactory factory = new PrevaylerFactory();
        factory.configurePrevalenceDirectory(dir);
        factory.configurePrevalentSystem(new Data());
        prevayler = factory.create();
    }

    //Carrega o arquivo de configuração e lê o diretório da base de dados
    private void carregaConfigurações() throws IOException, FileNotFoundException {
        //localPath = localPath.substring(0, localPath.lastIndexOf(sep));
       // String path = localPath.substring(localPath.lastIndexOf("jar:")+4);
        try{
            BufferedReader reader = new BufferedReader(new FileReader(path+sep+configFilename));
            //BufferedReader reader = new BufferedReader(new FileReader(configFilename));
            basedir = reader.readLine();
            reader.close();
        }catch(FileNotFoundException ex){
            //path = localPath.substring(localPath.lastIndexOf("jar:")+2);
            //System.out.println(path+sep+configFilename);
            File file = new File(path+sep+configFilename);
            BufferedWriter writer = new BufferedWriter(new FileWriter(file));
            writer.write(path+sep+basedir);
            writer.close();
            carregaConfigurações();
            System.out.println(ex.toString());
        }    
    }

    public void addAluno(Aluno aluno) {
        AlunoErro ae = dados.validaAluno(aluno);
        if(ae.getAluno()==aluno){
            prevayler.execute(new AddAluno(aluno));
            cbpm = new CBPastaModel(dados.getArrayPastas());
            jComboBox3.setModel(cbpm);
            jXTable1.repaint();
            jLabel4.setText(""+dados.getSize());
        }else{
            mostraDadosAluno(ae.getAluno(), ae.getErro());
        }
    }
    
    public void addAlunos(ArrayList<Aluno> alunos) {
        prevayler.execute(new AddAlunos(alunos));
        cbpm = new CBPastaModel(dados.getArrayPastas());
        jComboBox3.setModel(cbpm);
        jXTable1.repaint();
        jLabel4.setText("" + dados.getSize());
    }

    public void editAluno(Aluno a1, Aluno a2) {
        String nm = a2.getNome();
        String dt = a2.nscmToString();
        Integer rg = a2.getRg();
        Long cpf = a2.getCpf();
        if(nm.equals(a1.getNome()))
            nm = "aux123";
        if(rg!=null && rg.equals(a1.getRg()))
            rg = -1;
        if(cpf!=null && cpf.equals(a1.getCpf()))
            cpf = -1l;
        
        Aluno a3 = new Aluno(nm, a2.getResp(), -1, a2.getNscm(), rg, cpf);
        if(dt!=null && dt.equals(a1.nscmToString()))
            a3.setNscm(-1l);
        AlunoErro ae = dados.validaAluno(a3);
        if(ae.getAluno()==a3){
            //a2.setFicha(a1.getFicha());
            prevayler.execute(new AltAluno(a1, a2));
            jXTable1.repaint();
            JOptionPane.showMessageDialog(rootPane, "Registro modificado com sucesso!");
            preencherCampos(a2);
        }else
            mostraDadosAluno(ae.getAluno(), ae.getErro());   
    }
    
    public void mostraDadosAluno(Aluno a, String titulo){
        JOptionPane.showMessageDialog(rootPane, "Nome: " + a.getNome() + ".\nData de Nascimento: " + a.nscmToString()
                    + ".\nFicha: " + a.getFicha() + ".\nPasta: " + a.getPasta(), titulo, JOptionPane.ERROR_MESSAGE);
    }

    public void remAluno(Aluno aluno, boolean message) {
        prevayler.execute(new RemAluno(aluno));
        jLabel4.setText(""+dados.getSize());
        if(message)
            JOptionPane.showMessageDialog(rootPane, "Registro removido com sucesso!");
        int w = jXPanel1.getWidth();
        int h = jXPanel1.getHeight();
        jXPanel1.setSize(w-1, h-1);
       // jXPanel1.repaint();
  //      int w = this.getWidth();
   //     int h = this.getHeight();
        //this.pack();
        //this.setSize(w-1, h-1);
        //this.setSize(w, h);
        //jXTable1.packAll();
    }
    
    public void remAlunos() {
        prevayler.execute(new RemAlunos());
        jLabel4.setText(""+dados.getSize());
        int w = jXPanel1.getWidth();
        int h = jXPanel1.getHeight();
        jXPanel1.setSize(w-1, h-1);
       // jXPanel1.repaint();
  //      int w = this.getWidth();
   //     int h = this.getHeight();
        //this.pack();
        //this.setSize(w-1, h-1);
        //this.setSize(w, h);
        //jXTable1.packAll();
    }

    public void remAluno(int index) {
        //prevayler.execute(new RemAluno(index));
        jXTable1.repaint();
        JOptionPane.showMessageDialog(rootPane, "Registro removido com sucesso!");
        //resizeColumns();
    }

    private void createRibbonPanel() {
        addRibbonTaskBar();
        this.getRibbon().configureHelp(getResizableIconFromResource("resources/help_32.png"),
                new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        JOptionPane.showMessageDialog(rootPane, "Teste");
                    }
                });
        this.getRibbon().addTask(getFileTask());
        this.getRibbon().addTask(getConfiguracaoTask());
        this.getRibbon().addTask(getSobreTask());
        //this.getRibbon().addTask(getViewTask());
        //this.getRibbon().addTask(getRelatorioTask());
        this.createApplicationMenu();
    }

    private void createApplicationMenu() {
        RibbonApplicationMenu am = new RibbonApplicationMenu();
        ResizableIcon iri = getResizableIconFromResource("resources/export_32.png");//new ImageResizableIcon(ii);
        ActionListener act = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                exportarDadosExcel();
            }
        };
        am.addMenuEntry(new RibbonApplicationMenuEntryPrimary(iri, "Exportar para MSExcel (.xls)", act, JCommandButton.CommandButtonKind.ACTION_ONLY));
        
        ActionListener act3 = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                exportarDadosPdf();
            }
        };
        am.addMenuEntry(new RibbonApplicationMenuEntryPrimary(iri, "Exportar para PDF (.pdf)", act3, JCommandButton.CommandButtonKind.ACTION_ONLY));        
        am.addMenuSeparator();
        ResizableIcon iri2 = getResizableIconFromResource("resources/no_32.png");//new ImageResizableIcon(ii);
        ActionListener act2 = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                sair();
            }
        };
        am.addMenuEntry(new RibbonApplicationMenuEntryPrimary(iri2, "sair", act2, JCommandButton.CommandButtonKind.ACTION_ONLY));
        this.getRibbon().setApplicationMenu(am);
        appicon = getResizableIconFromResource("resources/arquivos_32.png");
        this.setApplicationIcon(appicon);
    }

    private RibbonTask getFileTask() {
        RibbonTask file = new RibbonTask("Arquivo", getImportBand(), getFiltroBand(), getExportBand());//getFileBand(), getImportBand(), getFiltroBand());
        return file;
    }
    
    private void sair(){
        System.exit(0);
    }
    
    private JRibbonBand getFiltroBand(){
        JRibbonBand filtroband = new JRibbonBand("Filtrar", null);
        JTextField tf = new JTextField(30);
        JComboBox cb = new JComboBox();
        cb.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Contém", "Igual" }));
        //JButton bt = new JButton("Filtrar");
        /*filtroband.addRibbonComponent(new JRibbonComponent(tf));
        filtroband.addRibbonComponent(new JRibbonComponent(cb));
        filtroband.addRibbonComponent(new JRibbonComponent(bt));*/
        
        filtroband.addRibbonComponent(new JRibbonComponent(jXPanel4),3);
        //filtroband.add
        ArrayList polices1 = new ArrayList();
        polices1.add(new CoreRibbonResizePolicies.None(filtroband.getControlPanel()));
        filtroband.setResizePolicies(polices1);
        return filtroband;
    }

    private JRibbonBand getFileBand() {
        JRibbonBand fileBand = new JRibbonBand("Arquivo", null);
        addCommandButtond("Novo", "resources/new_64.png", fileBand, RibbonElementPriority.TOP, null);
        ActionListener act = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                abrirButtonActionPerformed(e);
            }
        };
        addCommandButtond("Abrir", "resources/open_48.png", fileBand, RibbonElementPriority.MEDIUM, act);
        ActionListener act1 = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                salvarButtonActionPerformed(e);
            }
        };
        addCommandButtond("Salvar", "resources/save_32.png", fileBand, RibbonElementPriority.MEDIUM, act1);
        addCommandButtond("Salvar Como", "resources/saveas_32.png", fileBand, RibbonElementPriority.MEDIUM, null);
        ArrayList polices1 = new ArrayList();
        polices1.add(new CoreRibbonResizePolicies.None(fileBand.getControlPanel()));
        fileBand.setResizePolicies(polices1);
        return fileBand;
    }

    private void abrirButtonActionPerformed(ActionEvent evt) {
    }

    private void salvarButtonActionPerformed(ActionEvent evt) {
    }

    private JRibbonBand getImportBand() {
        JRibbonBand band = new JRibbonBand("Import", null);
        ActionListener act = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                openAddAlunoGui();
            }
        };
        ActionListener act1 = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                openPesquisaGui();
            }
        };
        addCommandButtond("Adicionar", "resources/add_32.png", band, RibbonElementPriority.TOP, act);
        addCommandButtond("Alunos (.pdf)", "resources/import_32.png", band, RibbonElementPriority.MEDIUM, act1);
        ArrayList polices1 = new ArrayList();
        polices1.add(new CoreRibbonResizePolicies.None(band.getControlPanel()));
        band.setResizePolicies(polices1);
        return band;
    }

    private void openAddAlunoGui() {
        AddAlunoGui aag = new AddAlunoGui(this, true);
        aag.setVisible(true);
    }
    
    private void openPesquisaGui() {
        for(int i=1902; i<10000; i++){
            Aluno a = new Aluno(""+i, ""+i, i, i, i, null);
            System.out.println(a.getNome());
            addAluno(a);
        }
    }

    private JRibbonBand getExportBand() {
        ActionListener act = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                exportarDadosExcel();
            }
        };
        ActionListener act1 = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                exportarDadosPdf();
            }
        };
        ActionListener act2 = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
            }
        };
        ActionListener act3 = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
            }
        };
        ActionListener act4 = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
            }
        };
        JRibbonBand band = new JRibbonBand("Export", null);
        addCommandButtond("Dados para Excel (.xls)", "resources/export_32.png", band, RibbonElementPriority.TOP, act);
        addCommandButtond("Dados para pdf (.pdf)", "resources/export_32.png", band, RibbonElementPriority.TOP, act1);
        //addCommandButtond("Notas (.pdf)", "resources/export_32.png", band, RibbonElementPriority.MEDIUM, act1);
        //addCommandButtond("Resultado Final (.pdf)", "resources/export_32.png", band, RibbonElementPriority.MEDIUM, act2);
        //addCommandButtond("Alunos em Recuperação 2º Semestre (.pdf)", "resources/export_32.png", band, RibbonElementPriority.MEDIUM, act3);
        //addCommandButtond("Recuperação 2º Semestre (.pdf)", "resources/export_32.png", band, RibbonElementPriority.MEDIUM, act4);
        ArrayList polices1 = new ArrayList();
        polices1.add(new CoreRibbonResizePolicies.None(band.getControlPanel()));
        band.setResizePolicies(polices1);
        return band;
    }
    
    private void exportarDadosPdf(){
        JFileChooser chooser = new JFileChooser();
        javax.swing.filechooser.FileFilter ff = new javax.swing.filechooser.FileFilter() {

            @Override
            public boolean accept(File pathname) {
                return pathname.getName().toLowerCase().endsWith(".pdf") || pathname.isDirectory();
            }
            public String getDescription() {
                return "Portable Document Format (.pdf)";
            }
        };
        chooser.setFileFilter(ff);
        //chooser.set
        int ok = chooser.showSaveDialog(this);
        String filename = chooser.getSelectedFile().getAbsolutePath();
        if (!filename.endsWith(".pdf")) {
            filename += ".pdf";
        }
        File f = new File(filename);
        int opok = JOptionPane.OK_OPTION;
        if (f.exists())
            opok = JOptionPane.showConfirmDialog(rootPane, "Deseja sobrescrever o arquivo?", "O Arquivo já Existe!", JOptionPane.YES_NO_OPTION);
        if(ok == JFileChooser.APPROVE_OPTION && opok == JOptionPane.OK_OPTION){
            
            try {
                Document doc = new Document(PageSize.A4);
                PdfWriter.getInstance(doc, new FileOutputStream(f));
                doc.open();
                float[] widths = {0.1f, 0.70f, 0.2f};
                ArrayList<Integer> pastas = dados.getPastasIDS();
                Font font = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD);
                for (Integer i : pastas) {
                    ArrayList<Aluno> alunos = dados.getAlunoPasta(i);
                    Collections.sort(alunos, new Comparator() {

                        @Override
                        public int compare(Object acc1, Object acc2) {
                            return ((Aluno) acc1).getFicha()-(((Aluno) acc2).getFicha());
                        }
                    });
                    PdfPTable table = new PdfPTable(widths);
                    table.setWidthPercentage(100f);
                    PdfPCell cel1 = new PdfPCell(new Phrase("FICHA"));
                    cel1.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
                    cel1.setBorderWidthLeft(0.3f);
                    cel1.setBorderColorLeft(BaseColor.WHITE);
                    cel1.setBackgroundColor(BaseColor.GRAY);
                    table.addCell(cel1);
                    PdfPCell cel2 = new PdfPCell(new Phrase("NOME DO ALUNO"));
                    cel2.setBackgroundColor(BaseColor.GRAY);
                    cel2.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
                    table.addCell(cel2);
                    PdfPCell cel3 = new PdfPCell(new Phrase("DT NASCIMENTO"));
                    cel3.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
                    cel3.setBorderWidthRight(0.3f);
                    cel3.setBorderColorRight(BaseColor.WHITE);
                    cel3.setBackgroundColor(BaseColor.GRAY);
                    table.addCell(cel3);
                    for (Aluno a : alunos) {
                        PdfPCell cell1 = new PdfPCell(new Phrase("" + a.getFicha(), font));
                        cell1.setHorizontalAlignment(Rectangle.ALIGN_RIGHT);
                        cell1.setBorderWidthLeft(0.3f);
                        cell1.setBorderColorLeft(BaseColor.WHITE);
                        table.addCell(cell1);
                        PdfPCell cell2 = new PdfPCell(new Phrase(a.getNome(), font));
                        table.addCell(cell2);
                        PdfPCell cell3 = new PdfPCell(new Phrase(a.nscmToString(), font));
                        cell3.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
                        cell3.setBorderWidthRight(0.3f);
                        cell3.setBorderColorRight(BaseColor.WHITE);
                        table.addCell(cell3);
                    }
                    doc.newPage();
                    Paragraph p1 = new Paragraph("ARQUIVO MORTO");
                    p1.setAlignment(Element.ALIGN_CENTER);
                    doc.add(p1);
                    Paragraph s = new Paragraph("");
                    doc.add(s);
                    Paragraph p = new Paragraph("Pasta: "+dados.getPastaTitle(i));
                    p.setAlignment(Element.ALIGN_CENTER);
                    doc.add(p);
                    doc.add(table);
                    GregorianCalendar gc1 = new GregorianCalendar();
                    gc1.setTimeInMillis(System.currentTimeMillis());
                    String rodape = "Gerado em: "+gc1.get(Calendar.DATE)+"/"+(gc1.get(Calendar.MONTH)+1)+"/"+gc1.get(Calendar.YEAR);
                    Chunk c = new Chunk(rodape);
                    Font rf = new Font(Font.FontFamily.TIMES_ROMAN, 6, Font.NORMAL);
                    c.setFont(rf);
                    Paragraph p2 = new Paragraph(c);
                    doc.add(p2);
                }
                doc.close();
            } catch (FileNotFoundException ex) {
                Logger.getLogger(MWRibbon.class.getName()).log(Level.SEVERE, null, ex);
            } catch (DocumentException ex) {
                Logger.getLogger(MWRibbon.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        
    }
    
    private void exportarDadosExcel(){
        JFileChooser chooser = new JFileChooser();
        int ok = chooser.showDialog(this, "Salvar");
        if(ok == JFileChooser.APPROVE_OPTION){
            String filename = chooser.getSelectedFile().getAbsolutePath();
            Excel e = new Excel(filename);
            ArrayList<Integer> pastas = dados.getPastasIDS();  
            //System.out.println(""+pastas.size());
            int plan = 0;
            for(Integer i : pastas){
                //System.out.println(dados.getPastaTitle(i));
                e.addPlanilha(dados.getPastaTitle(i), plan);
                e.addLabel(plan, "FICHA", 0, 0, 10, jxl.format.Alignment.CENTRE, jxl.format.Colour.RED);
                e.addLabel(plan, "NOME", 0, 1, 50, jxl.format.Alignment.CENTRE, jxl.format.Colour.RED);
                e.addLabel(plan, "RESPONSÁVEL", 0, 2, 50, jxl.format.Alignment.CENTRE, jxl.format.Colour.RED);
                e.addLabel(plan, "R.G.", 0, 3, 15, jxl.format.Alignment.CENTRE, jxl.format.Colour.RED);
                e.addLabel(plan, "C.P.F.", 0, 4, 15, jxl.format.Alignment.CENTRE, jxl.format.Colour.RED);
                e.addLabel(plan, "Dt. NASC.", 0, 5, 15, jxl.format.Alignment.CENTRE, jxl.format.Colour.RED);
                ArrayList<Aluno> alunos = dados.getAlunoPasta(i);
                for(Aluno a : alunos){
                    int l = a.getFicha();
                    l = l-1;
                    //if(l%50!=0)
                        l = l-((l/50)*50);
                    l = l+1;
                        Double id = ((Integer)a.getFicha()).doubleValue();
                    Integer rgi = a.getRg();
                    if(rgi!=null){
                        Double rg = a.getRg().doubleValue();
                        e.addNumber(plan, rg, l, 3, 15,jxl.format.Alignment.RIGHT, jxl.format.Colour.WHITE);
                    } else{
                        e.addLabel(plan, "", l, 3, 15,jxl.format.Alignment.RIGHT, jxl.format.Colour.WHITE);
                    }
                    Long cpfl = a.getCpf();
                    if(cpfl!=null){
                        Double cpf = a.getCpf().doubleValue();
                        e.addNumber(plan, cpf, l, 4, 15,jxl.format.Alignment.RIGHT, jxl.format.Colour.WHITE);
                    }else{
                        e.addLabel(plan, "", l, 4, 15,jxl.format.Alignment.RIGHT, jxl.format.Colour.WHITE);
                    }
                    e.addNumber(plan, id, l, 0, 10,jxl.format.Alignment.RIGHT, jxl.format.Colour.WHITE);
                    e.addLabel(plan, a.getNome(), l, 1, 50,jxl.format.Alignment.LEFT, jxl.format.Colour.WHITE);
                    e.addLabel(plan, a.getResp(), l, 2, 50,jxl.format.Alignment.LEFT, jxl.format.Colour.WHITE);
                    e.addLabel(plan, a.nscmToString(), l, 5, 15,jxl.format.Alignment.CENTRE, jxl.format.Colour.WHITE);
                }
                plan++;
            }
            e.save();
        }
    }

    private void addCommandButtond(String text, String icon, JRibbonBand band, RibbonElementPriority priority, ActionListener act) {
        JCommandButton button = new JCommandButton(text, getResizableIconFromResource(icon));
        button.addActionListener(act);
        band.addCommandButton(button, priority);
    }

    private void addCommandTogleButtond(String text, String icon, JRibbonBand band, RibbonElementPriority priority) {
        JCommandToggleButton button = new JCommandToggleButton(text, getResizableIconFromResource(icon));
        band.addCommandButton(button, priority);
        //band.addRibbonGalleryButtons("teste", "teste", button);
        //JCommandButtonStrip bs = new JCommandButtonStrip();
        //bs.add(button);
    }

    private RibbonTask getConfiguracaoTask() {
        RibbonTask task1 = new RibbonTask("Configurações", getBancoBand());//, getTurmasBand(), getDisciplinaBand(),
                //getProfessoresBand(), getAlunosBand(), getAtividadesBand());
        return task1;
    }
    
    private RibbonTask getSobreTask() {
        RibbonTask task1 = new RibbonTask("Sobre", getSobreBand());//, getTurmasBand(), getDisciplinaBand(),
                //getProfessoresBand(), getAlunosBand(), getAtividadesBand());
        return task1;
    }

    private JRibbonBand getBancoBand() {
        JRibbonBand band = new JRibbonBand("Banco de Dados", null);
        ActionListener act = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                changeDataBaseButtonActionPerformed(e);
            }
        };
        ActionListener act1 = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                backup();
            }
        };
        ActionListener act2 = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                backupDownload();
            }
        };
        addCommandButtond("Banco de Dados", "resources/banco_32.png", band, RibbonElementPriority.TOP, act);
        addCommandButtond("Backup", "resources/parameters_32.png", band, RibbonElementPriority.MEDIUM, act1);
        addCommandButtond("Carregar Backup", "resources/parameters_32.png", band, RibbonElementPriority.MEDIUM, act2);
        ArrayList polices1 = new ArrayList();
        polices1.add(new CoreRibbonResizePolicies.None(band.getControlPanel()));
        band.setResizePolicies(polices1);
        return band;
    }
    
    private JRibbonBand getSobreBand() {
        JRibbonBand band = new JRibbonBand("Sobre", null);
        ActionListener act = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                Sobre s = new Sobre(MWRibbon.this, false);
                s.pack();
                s.setLocationRelativeTo(MWRibbon.this);
                s.setVisible(true);
            }
        };
        addCommandButtond("Sobre", "resources/banco_32.png", band, RibbonElementPriority.TOP, act);
        ArrayList polices1 = new ArrayList();
        polices1.add(new CoreRibbonResizePolicies.None(band.getControlPanel()));
        band.setResizePolicies(polices1);
        return band;
    }

    private void changeDataBaseButtonActionPerformed(ActionEvent evt) {
        path = localPath.substring(localPath.lastIndexOf("jar:")+4);
        JFileChooser chooser = new JFileChooser();
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setDialogTitle("Alterar Base de Dados");
        //System.out.println(""+ok);
        if(chooser.showDialog(this, "Ok")==JOptionPane.OK_OPTION){
            BufferedWriter writer = null;
            try{
                File file = new File(path+sep+configFilename);
                writer = new BufferedWriter(new FileWriter(file));
                writer.write(chooser.getSelectedFile().getAbsolutePath());
                basedir = chooser.getSelectedFile().getAbsolutePath();
                //carregaConfigurações();
                try {
                    startPrevayler(basedir);
                    //System.out.println(basedir);
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(MWRibbon.class.getName()).log(Level.SEVERE, null, ex);
                }
                carregaDados();
            } catch (IOException ex) {
                Logger.getLogger(MWRibbon.class.getName()).log(Level.SEVERE, null, ex);
            } finally {
                try {
                    writer.close();
                } catch (IOException ex) {
                    Logger.getLogger(MWRibbon.class.getName()).log(Level.SEVERE, null, ex);
                }
            }    
        }
    }

    private JRibbonBand getTurmasBand() {
        JRibbonBand band = new JRibbonBand("Turmas", null);
        addCommandButtond("Adicionar", "resources/add_32.png", band, RibbonElementPriority.TOP, null);
        addCommandButtond("Editar", "resources/edit.png", band, RibbonElementPriority.MEDIUM, null);
        addCommandButtond("Remover", "resources/rem_32.png", band, RibbonElementPriority.MEDIUM, null);
        ArrayList polices1 = new ArrayList();
        polices1.add(new CoreRibbonResizePolicies.None(band.getControlPanel()));
        band.setResizePolicies(polices1);
        return band;
    }

    private JRibbonBand getProfessoresBand() {
        JRibbonBand band = new JRibbonBand("Professores", null);
        addCommandButtond("Adicionar", "resources/add_32.png", band, RibbonElementPriority.TOP, null);
        addCommandButtond("Editar", "resources/edit.png", band, RibbonElementPriority.MEDIUM, null);
        addCommandButtond("Remover", "resources/rem_32.png", band, RibbonElementPriority.MEDIUM, null);
        ArrayList polices1 = new ArrayList();
        polices1.add(new CoreRibbonResizePolicies.None(band.getControlPanel()));
        band.setResizePolicies(polices1);
        return band;
    }

    private JRibbonBand getDisciplinaBand() {
        JRibbonBand band = new JRibbonBand("Disciplinas", null);
        addCommandButtond("Adicionar", "resources/add_32.png", band, RibbonElementPriority.TOP, null);
        addCommandButtond("Editar", "resources/edit.png", band, RibbonElementPriority.MEDIUM, null);
        addCommandButtond("Remover", "resources/rem_32.png", band, RibbonElementPriority.MEDIUM, null);
        ArrayList polices1 = new ArrayList();
        polices1.add(new CoreRibbonResizePolicies.None(band.getControlPanel()));
        band.setResizePolicies(polices1);
        return band;
    }

    private JRibbonBand getAlunosBand() {
        JRibbonBand band = new JRibbonBand("Alunos", null);
        ActionListener act = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                addAlunoButtonActionPerformed(e);
            }
        };
        addCommandButtond("Adicionar", "resources/add_32.png", band, RibbonElementPriority.TOP, act);
        ActionListener act2 = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                remAlunoButtonActionPerformed(e);
            }
        };
        addCommandButtond("Editar", "resources/edit.png", band, RibbonElementPriority.TOP, null);
        addCommandButtond("Remover", "resources/rem_32.png", band, RibbonElementPriority.TOP, act2);

        ActionListener act1 = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                importAlunotxtButtonActionPerformed(e);
            }
        };
        addCommandButtond("Import (.txt)", "resources/import_32.png", band, RibbonElementPriority.MEDIUM, act1);
        addCommandButtond("Import (.pdf)", "resources/import_32.png", band, RibbonElementPriority.MEDIUM, null);
        ArrayList polices1 = new ArrayList();
        polices1.add(new CoreRibbonResizePolicies.Mid2Mid(band.getControlPanel()));
        //polices1.add(new IconRibbonBandResizePolicy(band.getControlPanel()));
        band.setResizePolicies(polices1);
        return band;
    }

    private void addAlunoButtonActionPerformed(ActionEvent evt) {
    }

    private void remAlunoButtonActionPerformed(ActionEvent evt) {
    }

    private void importAlunotxtButtonActionPerformed(ActionEvent evt) {
    }

    private JRibbonBand getAtividadesBand() {
        JRibbonBand band = new JRibbonBand("Atividades", null);
        addCommandButtond("Adicionar", "resources/add_32.png", band, RibbonElementPriority.TOP, null);
        addCommandButtond("Editar", "resources/edit.png", band, RibbonElementPriority.MEDIUM, null);
        addCommandButtond("Remover", "resources/rem_32.png", band, RibbonElementPriority.MEDIUM, null);
        ArrayList polices1 = new ArrayList();
        polices1.add(new CoreRibbonResizePolicies.None(band.getControlPanel()));
        band.setResizePolicies(polices1);
        return band;
    }

    private RibbonTask getViewTask() {
        RibbonTask task1 = new RibbonTask("Visualizar", getViewBand(), getSitAlunosBand());
        return task1;
    }

    private JRibbonBand getViewBand() {
        JRibbonBand band = new JRibbonBand("Visualização", null);
        addCommandTogleButtond("Notas", "resources/related_32.png", band, RibbonElementPriority.TOP);
        addCommandTogleButtond("Disciplinas", "resources/subjects.png", band, RibbonElementPriority.MEDIUM);
        addCommandTogleButtond("Professores", "resources/teachers.png", band, RibbonElementPriority.MEDIUM);
        addCommandTogleButtond("Turmas", "resources/class_32.png", band, RibbonElementPriority.MEDIUM);
        //JCommandToggleMenuButton x = new JCommandToggleMenuButton(null, null)

        ArrayList polices1 = new ArrayList();
        polices1.add(new CoreRibbonResizePolicies.None(band.getControlPanel()));
        band.setResizePolicies(polices1);
        return band;
    }

    private JRibbonBand getSitAlunosBand() {
        JRibbonBand band = new JRibbonBand("Alunos", null);
        addCommandButtond("Todos", "resources/summary_class.png", band, RibbonElementPriority.TOP, null);
        addCommandButtond("Aprovados", "resources/ungroup_48.png", band, RibbonElementPriority.MEDIUM, null);
        addCommandButtond("Reprovados", "resources/clearclasses_32.png", band, RibbonElementPriority.MEDIUM, null);
        ArrayList polices1 = new ArrayList();
        polices1.add(new CoreRibbonResizePolicies.None(band.getControlPanel()));
        band.setResizePolicies(polices1);
        return band;
    }

    private void addRibbonTaskBar() {
        JCommandButton button = new JCommandButton("teste", getResizableIconFromResource("resources/clearclasses_32.png"));
        this.getRibbon().addTaskbarComponent(button);
    }

    private RibbonTask getRelatorioTask() {
        RibbonTask task1 = new RibbonTask("Relatório", getPresencaBand(), getSitAlunosBand());
        return task1;
    }

    private JRibbonBand getPresencaBand() {
        JRibbonBand band = new JRibbonBand("Lista de Presença", null);
        ActionListener act = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                //gerarListasPresenca(e);
            }
        };
        addCommandButtond("Lista de Presença", "resources/related_32.png", band, RibbonElementPriority.TOP, act);
        ArrayList polices1 = new ArrayList();
        polices1.add(new CoreRibbonResizePolicies.None(band.getControlPanel()));
        band.setResizePolicies(polices1);
        return band;
    }

    public static ResizableIcon getResizableIconFromResource(String resource) {
        return ImageWrapperResizableIcon.getIcon(MWRibbon.class.getClassLoader().getResource(resource), new Dimension(64, 64));
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jXPanel4 = new org.jdesktop.swingx.JXPanel();
        jButton1 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jComboBox2 = new javax.swing.JComboBox();
        jTextField5 = new javax.swing.JTextField();
        jXLabel11 = new org.jdesktop.swingx.JXLabel();
        jComboBox3 = new javax.swing.JComboBox();
        jXPanel3 = new org.jdesktop.swingx.JXPanel();
        jXLabel1 = new org.jdesktop.swingx.JXLabel();
        jTextField1 = new javax.swing.JTextField();
        jXLabel2 = new org.jdesktop.swingx.JXLabel();
        jXLabel3 = new org.jdesktop.swingx.JXLabel();
        jTextField3 = new javax.swing.JTextField();
        jXLabel4 = new org.jdesktop.swingx.JXLabel();
        jTextField4 = new javax.swing.JTextField();
        jXLabel5 = new org.jdesktop.swingx.JXLabel();
        jTextField2 = new javax.swing.JTextField();
        jXLabel6 = new org.jdesktop.swingx.JXLabel();
        jXLabel7 = new org.jdesktop.swingx.JXLabel();
        jXLabel8 = new org.jdesktop.swingx.JXLabel();
        jXLabel9 = new org.jdesktop.swingx.JXLabel();
        jFormattedTextField1 = new javax.swing.JFormattedTextField();
        jFormattedTextField2 = new javax.swing.JFormattedTextField();
        jXLabel10 = new org.jdesktop.swingx.JXLabel();
        jButton3 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jDateChooser1 = new com.toedter.calendar.JDateChooser();
        jXPanel2 = new org.jdesktop.swingx.JXPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jXBusyLabel1 = new org.jdesktop.swingx.JXBusyLabel();
        jXPanel1 = new org.jdesktop.swingx.JXPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jXTable1 = new org.jdesktop.swingx.JXTable();

        jXPanel4.setPreferredSize(new java.awt.Dimension(440, 100));

        jButton1.setText("Filtrar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0));

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Nome:", "Pasta", "R.G.:", "C.P.F.:" }));
        jComboBox2.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBox2ItemStateChanged(evt);
            }
        });
        jPanel1.add(jComboBox2);

        jTextField5.setPreferredSize(new java.awt.Dimension(350, 27));
        jPanel1.add(jTextField5);

        jXLabel11.setText("Total de Registros:");

        javax.swing.GroupLayout jXPanel4Layout = new javax.swing.GroupLayout(jXPanel4);
        jXPanel4.setLayout(jXPanel4Layout);
        jXPanel4Layout.setHorizontalGroup(
            jXPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jXPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 416, Short.MAX_VALUE)
                    .addGroup(jXPanel4Layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addGap(18, 18, 18)
                        .addComponent(jXLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jXPanel4Layout.setVerticalGroup(
            jXPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jXPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jXLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(26, Short.MAX_VALUE))
        );

        jComboBox3.setModel(cbpm);
        jComboBox3.setSelectedIndex(0);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Arquivo Morto");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jXPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Dados do Cadastro", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, java.awt.Color.blue));
        jXPanel3.setPreferredSize(new java.awt.Dimension(350, 420));

        jXLabel1.setText("Nome:");

        jXLabel2.setText("Data Nascmento:");

        jXLabel3.setText("Pasta:");

        jTextField3.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTextField3.setEnabled(false);

        jXLabel4.setText("Ficha:");

        jTextField4.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTextField4.setEnabled(false);

        jXLabel5.setText("Responsável:");

        jXLabel6.setForeground(java.awt.Color.red);
        jXLabel6.setText("dd/mm/aaaa");
        jXLabel6.setFont(new java.awt.Font("Ubuntu", 0, 12)); // NOI18N

        jXLabel7.setText("R.G.:");

        jXLabel8.setForeground(java.awt.Color.red);
        jXLabel8.setText("Somente Números (opcional)");
        jXLabel8.setFont(new java.awt.Font("Ubuntu", 0, 12)); // NOI18N

        jXLabel9.setText("C.P.F.:");

        jFormattedTextField1.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(java.text.NumberFormat.getIntegerInstance())));
        jFormattedTextField1.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        try {
            jFormattedTextField2.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jFormattedTextField2.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        jXLabel10.setForeground(java.awt.Color.red);
        jXLabel10.setText("Somente Números (opcional)");
        jXLabel10.setFont(new java.awt.Font("Ubuntu", 0, 12)); // NOI18N

        jButton3.setText("Remover");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton2.setText("Alterar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jXPanel3Layout = new javax.swing.GroupLayout(jXPanel3);
        jXPanel3.setLayout(jXPanel3Layout);
        jXPanel3Layout.setHorizontalGroup(
            jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jXPanel3Layout.createSequentialGroup()
                        .addComponent(jXLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jXPanel3Layout.createSequentialGroup()
                        .addGroup(jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextField2)
                            .addComponent(jTextField1)
                            .addGroup(jXPanel3Layout.createSequentialGroup()
                                .addComponent(jXLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 75, Short.MAX_VALUE)
                                .addComponent(jXLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jXPanel3Layout.createSequentialGroup()
                                .addGroup(jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jFormattedTextField1)
                                    .addComponent(jFormattedTextField2))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jXLabel8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jXLabel10, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jXPanel3Layout.createSequentialGroup()
                                .addGroup(jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jXLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jXLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jXLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jXLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jXPanel3Layout.createSequentialGroup()
                                        .addComponent(jDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jXLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(24, 24, 24)))
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addGroup(jXPanel3Layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(jButton2)
                                .addGap(18, 18, 18)
                                .addComponent(jButton3)))
                        .addContainerGap())))
        );
        jXPanel3Layout.setVerticalGroup(
            jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jXLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(30, 30, 30)
                .addComponent(jXLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(23, 23, 23)
                .addComponent(jXLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jXLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jXLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jFormattedTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jXLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(7, 7, 7)
                .addGroup(jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jXLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jFormattedTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
                .addGroup(jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton3))
                .addContainerGap())
        );

        jFormattedTextField1.setFocusLostBehavior(JFormattedTextField.COMMIT);
        jFormattedTextField2.setFocusLostBehavior(JFormattedTextField.COMMIT);

        getContentPane().add(jXPanel3, java.awt.BorderLayout.EAST);

        jXPanel2.setPreferredSize(new java.awt.Dimension(829, 70));

        jLabel1.setText("Base de Dados:");

        jLabel2.setText("Total de Registros:");

        javax.swing.GroupLayout jXPanel2Layout = new javax.swing.GroupLayout(jXPanel2);
        jXPanel2.setLayout(jXPanel2Layout);
        jXPanel2Layout.setHorizontalGroup(
            jXPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jXPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jXPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 584, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 342, Short.MAX_VALUE))
                    .addGroup(jXPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jXBusyLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jXPanel2Layout.setVerticalGroup(
            jXPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jXPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jXPanel2Layout.createSequentialGroup()
                        .addGroup(jXPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(jXPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jXPanel2Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jXBusyLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(20, 20, 20))))
        );

        getContentPane().add(jXPanel2, java.awt.BorderLayout.PAGE_END);

        jXPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Registros", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, java.awt.Color.blue));
        jXPanel1.setPreferredSize(new java.awt.Dimension(14, 420));
        jXPanel1.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                jXPanel1ComponentResized(evt);
            }
        });
        jXPanel1.setLayout(new java.awt.BorderLayout());

        jXTable1.setModel(atm);
        jXTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jXTable1MouseClicked(evt);
            }
        });
        jXTable1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jXTable1KeyReleased(evt);
            }
        });
        jScrollPane1.setViewportView(jXTable1);
        jXTable1.setSelectionMode(0);
        jXTable1.setGridColor(Color.gray);
        jXTable1.setShowGrid(true);
        tcm = jXTable1.getColumnModel();
        tcm.getColumn(0).setResizable(false);
        tcm.getColumn(2).setResizable(false);
        tcm.getColumn(3).setResizable(false);
        jXTable1.getColumnModel().getColumn(0).setPreferredWidth(60);
        jXTable1.getColumnModel().getColumn(2).setPreferredWidth(100);
        jXTable1.getColumnModel().getColumn(3).setPreferredWidth(300);

        jXPanel1.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        getContentPane().add(jXPanel1, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jXTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jXTable1MouseClicked
//        int row = jXTable1.getSelectedRow();
//        if(row>-1){
            Aluno aluno = atm.getAlunos().get(modelRow);
            preencherCampos(aluno);
//        }
    }//GEN-LAST:event_jXTable1MouseClicked

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        int id = Integer.parseInt(jTextField4.getText());
        String nm = jTextField1.getText();
        String resp = jTextField2.getText();
        Long nscm;
        try {
            nscm = jDateChooser1.getDate().getTime();
        } catch (NullPointerException ex) {
            JOptionPane.showMessageDialog(rootPane, "A data de nascimento precisa ser informada");
            preencherCampos(dados.getAlunoFicha(id));
            return;
        }
        Integer rg = null;
        Long cpf = null;
        try {   
            if(!jFormattedTextField1.getText().equals(""))
                rg = Integer.parseInt(jFormattedTextField1.getText().replace(".", ""));
        } catch (NumberFormatException ex) {
            JOptionPane.showMessageDialog(rootPane, "Formato do RG inválido!", "Erro", JOptionPane.ERROR_MESSAGE);
            preencherCampos(dados.getAlunoFicha(id));
            return;
        }
        try {   
            if(!jFormattedTextField2.getText().equals("   .   .   -  "))
                cpf = Long.parseLong(jFormattedTextField2.getText().replace(".", "").replace("-", ""));
        } catch (NumberFormatException ex) {
            JOptionPane.showMessageDialog(rootPane, "Formato do CPF inválido!", "Erro", JOptionPane.ERROR_MESSAGE);
            preencherCampos(dados.getAlunoFicha(id));
            return;
        }
        Aluno a1 = dados.getAlunoFicha(id);
        Aluno a2 = new Aluno(nm, resp, id, nscm, rg, cpf);
        /*AlunoErro ae = dados.validaAluno(a2);
        if(ae.getAluno()!=null && ae.getAluno()==a2)*/
        this.editAluno(a1, a2);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        int id = (Integer) jXTable1.getValueAt(jXTable1.getSelectedRow(), 0);
        Aluno a = dados.getAlunoFicha(id);
        this.remAluno(a, true);
        atm.setAlunos(dados.getArrayAlunos());
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        jXTable1.clearSelection();
        switch (jComboBox2.getSelectedIndex()) {
            case 0:
                if (jTextField5.getText().equals("")) {
                    atm.setAlunos(dados.getArrayAlunos());
                    jXLabel11.setText("Total de Registros: "+dados.getArrayAlunos().size());
                    break;
                } else {
                    ArrayList<Aluno> alns = new ArrayList<Aluno>();
                    for (Aluno a : dados.getArrayAlunos()) {
                        if (a.getNome().contains(jTextField5.getText().toUpperCase())) {
                            alns.add(a);
                        }
                    }
                    atm.setAlunos(alns);
                    jXLabel11.setText("Total de Registros: "+alns.size());
                    break;
                }
            case 1:
                if(jComboBox3.getSelectedIndex()==0){
                    atm.setAlunos(dados.getArrayAlunos());
                    jXLabel11.setText("Total de Registros: "+dados.getArrayAlunos().size());
                    break;
                }
                String s = (String)jComboBox3.getSelectedItem();
                int p = Integer.parseInt(s.substring(0, s.indexOf("-")));
                //System.out.println(""+dados.getAlunoPasta(p).size());
                atm.setAlunos(dados.getAlunoPasta(p));
                jXLabel11.setText("Total de Registros: "+dados.getAlunoPasta(p).size());
                break;
            case 2:
                try{
                    if(jTextField5.getText().equals("")){
                        atm.setAlunos(dados.getArrayAlunos());
                        jXLabel11.setText("Total de Registros: "+dados.getArrayAlunos().size());
                        break;
                    }
                    int rg = Integer.parseInt(jTextField5.getText());
                    ArrayList<Aluno> aln = new ArrayList<Aluno>();
                    if(dados.getAlunoRg(rg)!=null)
                        aln.add(dados.getAlunoRg(rg));
                    atm.setAlunos(aln);
                    jXLabel11.setText("Total de Registros: "+aln.size());
                    break;
                }catch(NumberFormatException ex){
                    JOptionPane.showMessageDialog(rootPane, "O RG deve conter apenas números");
                    break;
                }
            case 3:
                try{
                    if(jTextField5.getText().equals("")){
                        atm.setAlunos(dados.getArrayAlunos());
                        jXLabel11.setText("Total de Registros: "+dados.getArrayAlunos().size());
                        break;
                    }
                    long cpf = Long.parseLong(jTextField5.getText());
                    ArrayList<Aluno> aln = new ArrayList<Aluno>();
                    if(dados.getAlunoCpf(cpf)!=null)
                        aln.add(dados.getAlunoCpf(cpf));
                    atm.setAlunos(aln);
                    jXLabel11.setText("Total de Registros: "+aln.size());
                    break;
                }catch(NumberFormatException ex){
                    JOptionPane.showMessageDialog(rootPane, "O CPF deve conter apenas números");
                    break;
                }
        }
        int w = jXPanel1.getWidth();
        int h = jXPanel1.getHeight();
        jXPanel1.setSize(w-1, h-1);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        try {
            prevayler.takeSnapshot();
        } catch (IOException ex) {
            Logger.getLogger(MWRibbon.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_formWindowClosing

    private void jComboBox2ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBox2ItemStateChanged
        jPanel1.removeAll();
        jPanel1.add(jComboBox2);
        switch (jComboBox2.getSelectedIndex()) {
            case 0:
                jPanel1.add(jTextField5);
                break;
            case 1:
                jPanel1.add(jComboBox3);
                break;
            case 2:
                jPanel1.add(jTextField5);
                break;
            case 3:
                jPanel1.add(jTextField5);
                break;
        }
    }//GEN-LAST:event_jComboBox2ItemStateChanged

    private void jXPanel1ComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jXPanel1ComponentResized
        resizeColumns();
    }//GEN-LAST:event_jXPanel1ComponentResized

    private void jXTable1KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jXTable1KeyReleased
        /*int row = jXTable1.getSelectedRow();
        System.out.println(""+row);*/
        Aluno aluno = atm.getAlunos().get(modelRow);
        preencherCampos(aluno);
    }//GEN-LAST:event_jXTable1KeyReleased

    //Redimensiona as colunas de acordo com a largura do jpanel1
    public void resizeColumns(){
        //jXTable1.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
        int w = jXPanel1.getWidth();   
        //jXTable1.getColumnModel().getColumn(0).setPreferredWidth(60);
        jXTable1.getColumnModel().getColumn(1).setPreferredWidth(w - 400);
        //jXTable1.getColumnModel().getColumn(2).setPreferredWidth(100);
        //jXTable1.getColumnModel().getColumn(3).setPreferredWidth(100);
        //jXTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        //System.out.println("resizecolumns "+w);
    }
    
    
    private void limparCampos() {
        jTextField1.setText("");
        jDateChooser1.setDate(gc.getTime());
        jTextField3.setText("");
        jTextField4.setText("");
        jXTable1.clearSelection();
    }

    private void preencherCampos(Aluno aluno) {
        GregorianCalendar cal = new GregorianCalendar();
        cal.setTimeInMillis(aluno.getNscm());
        jTextField1.setText(aluno.getNome());
        if (aluno.getResp() != null) {
            jTextField2.setText(aluno.getResp());
        }
        jDateChooser1.setDate(cal.getTime());
        jTextField3.setText("" + aluno.getPasta());
        jTextField4.setText("" + aluno.getFicha());
        if (aluno.getRg() != null) {
            //jFormattedTextField1.setValue(aluno.getRg());
            jFormattedTextField1.setText("" + aluno.getRg());
        } else {
            jFormattedTextField1.setText("");
        }
        if (aluno.getCpf() != null) {
            jFormattedTextField2.setText("" + aluno.getCpf());
        } else {
            jFormattedTextField2.setText("");
        }
        jFormattedTextField1.repaint();
        jFormattedTextField2.repaint();
    }
    
    public void backupDownload(){
        JFileChooser chooser = new JFileChooser();
        chooser.setDialogTitle("Selecione o Diretório do Banco de Dados");
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int ok = chooser.showDialog(this, "Ok");
        if(ok>=0){
            jXBusyLabel1.setBusy(true);
            jXBusyLabel1.setText("Preparando carga de dados");
            ArrayList<Aluno> alunos = (ArrayList<Aluno>) dados.getArrayAlunos().clone();
            /*for (Aluno a : alunos) {
                remAluno(a, false);
            }*/
            remAlunos();
            jXBusyLabel1.setBusy(false);
            Thread t = new Thread(new BackupDownload(chooser.getSelectedFile().getAbsolutePath(), jXBusyLabel1, dados.getArrayAlunos(), this));
            t.start();            
        }
    }
    
    public void mergeData(){
        JFileChooser chooser = new JFileChooser();
        chooser.setDialogType(JFileChooser.DIRECTORIES_ONLY);
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        //chooser.showDialog(this, "Ok");
        if(chooser.showDialog(this, "Ok")==JOptionPane.OK_OPTION){
            PrevaylerFactory factory = new PrevaylerFactory();
            try {
                //System.out.println(chooser.getSelectedFile().getAbsoluteFile());
                //System.out.println(chooser.getSelectedFile().getCanonicalPath());
                factory.configurePrevalenceDirectory(chooser.getSelectedFile().getAbsolutePath());
                factory.configurePrevalentSystem(new Data());
                Prevayler prev = factory.create();
                Data d = ((Data) prev.prevalentSystem());
                for (Aluno a : d.getArrayAlunos()) {
                    if(!dados.contem(a))
                        addAluno(a);
                }
                carregaDados();
                JOptionPane.showMessageDialog(this, "Dados Carregados com sucesso!");
            } catch (IOException ex) {
                Logger.getLogger(MWRibbon.class.getName()).log(Level.SEVERE, null, ex);
                JOptionPane.showMessageDialog(this, "Problema na carga dos dados");
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(MWRibbon.class.getName()).log(Level.SEVERE, null, ex);
                JOptionPane.showMessageDialog(this, "Problema na carga dos dados");
            }
        }
    }
    
    public void backup(){
        JFileChooser chooser = new JFileChooser();
        chooser.setDialogTitle("Selecione o Diretório para Backup");
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int ok = chooser.showDialog(this, "Ok");
        if(ok==JFileChooser.APPROVE_OPTION){
            Thread t = new Thread(new Backup(chooser.getSelectedFile().getAbsolutePath(), jXBusyLabel1, dados.getArrayAlunos(), this));
            t.start();
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MWRibbon.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MWRibbon.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MWRibbon.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MWRibbon.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new MWRibbon().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JComboBox jComboBox3;
    private com.toedter.calendar.JDateChooser jDateChooser1;
    private javax.swing.JFormattedTextField jFormattedTextField1;
    private javax.swing.JFormattedTextField jFormattedTextField2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private org.jdesktop.swingx.JXBusyLabel jXBusyLabel1;
    private org.jdesktop.swingx.JXLabel jXLabel1;
    private org.jdesktop.swingx.JXLabel jXLabel10;
    private org.jdesktop.swingx.JXLabel jXLabel11;
    private org.jdesktop.swingx.JXLabel jXLabel2;
    private org.jdesktop.swingx.JXLabel jXLabel3;
    private org.jdesktop.swingx.JXLabel jXLabel4;
    private org.jdesktop.swingx.JXLabel jXLabel5;
    private org.jdesktop.swingx.JXLabel jXLabel6;
    private org.jdesktop.swingx.JXLabel jXLabel7;
    private org.jdesktop.swingx.JXLabel jXLabel8;
    private org.jdesktop.swingx.JXLabel jXLabel9;
    private org.jdesktop.swingx.JXPanel jXPanel1;
    private org.jdesktop.swingx.JXPanel jXPanel2;
    private org.jdesktop.swingx.JXPanel jXPanel3;
    private org.jdesktop.swingx.JXPanel jXPanel4;
    private org.jdesktop.swingx.JXTable jXTable1;
    // End of variables declaration//GEN-END:variables
}
